﻿@namespace SE.PO.CInterface.Web.Pages.DB.Area
@page "/db/areas"
@using SE.PO.CInterface.Web.Clients
@using SE.PO.CInterface.DBProtocols.Areas
@inject AreaClient AreaClient
<PageContainer Title="区域">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>首页</BreadcrumbItem>
            <BreadcrumbItem>数据库协议</BreadcrumbItem>
            <BreadcrumbItem>区域</BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <Content>
        <span>下级SC把监控对象配置根据“数据库接口定义”的数据结构存储到中间数据库表中，增加、修改和删除任何配置，下级SC必须保证能够及时的维护该中间数据库表中的数据。涉及到的中间数据库表有M_Area、M_Site、M_Room、M_Device、M_SIGNAL，M_SU，NodeModify，NodeUpdate。中间数据库表中的数据除了NodeUpdate外均由下级SC维护，下级SC保证上述表中的数据和下级SC的配置一致；NodeUpdate表由上级SC负责添加数据，下级SC定时获取数据并维护（删除）。</span>
    </Content>
    <ChildContent>
        <Card>
            <Button OnClick="@(() => { _addVisible = true; })" Type="primary" Style="margin-bottom:16px">
                新增区域
            </Button>
            <Button OnClick="@DeleteSelectedRows" Type="danger" Style="margin-bottom:16px">
                删除选定
            </Button>
            <Table @ref="_table"
                   TItem="AreaDto"
                   DataSource="@_source"
                   Total="_total"
                   @bind-PageIndex="_pageIndex"
                   @bind-PageSize="_pageSize"
                   @bind-SelectedRows="_selectedRows"
                   OnChange="OnChange"
                   Size="TableSize.Small">
                <Selection Key="@(context.Id)"/>
                <PropertyColumn  Title="下级SCID" Property="c => c.ScId" />
                <PropertyColumn  Title="区域编码" Property="c => c.Id" />
                <PropertyColumn  Title="上级区域ID" Property="c => c.LastAreaId"/>
                <PropertyColumn  Title="区域名称" Property="c => c.AreaName" />
                <ActionColumn Width="160" Title="操作" Fixed="right">
                    <Space>
                        <SpaceItem>
                            <Button Danger OnClick="@(() => { _delVisible = true; Delete(context.Id);})">删 除</Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button OnClick="@(() => { _editVisible = true; Edit(context.Id);})">修 改</Button>
                        </SpaceItem>
                    </Space>
                </ActionColumn>
            </Table>
        </Card>
    </ChildContent>
</PageContainer>

<Modal Title="新增区域"
       Centered="true"
       Visible="@_addVisible"
       OnOk="@AddHandleOk"
       OnCancel="@AddHandleCancel">
    <AddAreaFrom @ref="_addAreaFrom"
                 OnSuccess="async () => { _addVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                 OnFailure="() => { _addVisible = true; }"
                 OnCancel="() => { _addVisible = true; }" >
    </AddAreaFrom>
</Modal>

<Modal Title="编辑区域"
       Centered="true"
       Visible="@_editVisible"
       OnOk="@EditHandleOk"
       OnCancel="@EditHandleCancel">
    <EditAreaFrom @ref="_editAreaFrom"
                  Model="@_editModel"
                  OnSuccess="async () => { _editVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                  OnFailure="() => { _editVisible = true; }"
                  OnCancel="() => { _editVisible = true; }">
    </EditAreaFrom>
</Modal>

<Modal Title="删除区域"
       Centered="true"
       Visible="@_delVisible"
       OnOk="@DeleteHandleOk"
       OnCancel="@DeleteHandleCancel">
    <DelAreaFrom @ref="_delAreaFrom"
                 Model="DelModel"
                 Models="@DelModels"
                 OnSuccess="async () => { _delVisible = false; await GetSourceAsync(_pageIndex, _pageSize);}"
                 OnFailure="() => { _delVisible = true; }"
                 OnCancel="() => { _delVisible = true; }">
    </DelAreaFrom>
</Modal>